﻿/*
=======================================================
    SuperUser【超级用户】
=======================================================
*/

namespace Services
{
    public interface ISuperUserLogic : ILogic<SuperUserModel, SuperUserFilterModel>
    {
        UserModel GetUserByLogin(string loginName, string password);
    }


    public class SuperUserLogic : BaseLogic<SuperUserModel, SuperUserFilterModel, SuperUser, ISuperUserRepository, ISuperUserMapping, ISuperUserService>, ISuperUserLogic
    {
        public SuperUserLogic(ICurrentUser currentUser, ISuperUserRepository repository, ISuperUserMapping mapping, ISuperUserService service)
            : base(currentUser, repository, mapping, service)
        {
        }

        public UserModel GetUserByLogin(string loginName, string password)
        {
            var user = _repository.GetUserByLogin(loginName, password);

            if (user.IsEmpty())
            {
                throw new CustomException("用户名、密码输入错误！");
            }

            return new UserModel
            {
                LoginUserType = LoginUserType.超级用户,
                LoginTypeID = -1,
                UserID = user.SuperUserID,
                Name = user.Name,
            };
        }
    }
}
